export const formatYMD = (value: string | number | Date) => {
  const date = new Date(value)
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  const formattedDate = year + '-' + ('0' + month).slice(-2) + '-' + ('0' + day).slice(-2) // 例如: "2023-04-05"
  return formattedDate
}

export const formatYMDHM = (value: string | number | Date) => {
  const date = new Date(value)
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const h = date.getHours()
  let m = date.getMinutes()

  const formattedDate =
    year +
    '-' +
    ('0' + month).slice(-2) +
    '-' +
    ('0' + day).slice(-2) +
    ' ' +
    ('0' + h).slice(-2) +
    ':' +
    ('0' + m).slice(-2) +
    ':00' // 例如: "2023-04-05"
  return formattedDate
}

export const formatHMS = (value: string | number | Date) => {
  const date = new Date(value)
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const h = date.getHours()
  let m = date.getMinutes()
  if (m < 15) {
    m = 0
  } else if (m < 30) {
    m = 15
  } else if (m < 45) {
    m = 30
  } else {
    m = 45
  }
  const formattedDate =
    year +
    '-' +
    ('0' + month).slice(-2) +
    '-' +
    ('0' + day).slice(-2) +
    ' ' +
    ('0' + h).slice(-2) +
    ':' +
    ('0' + m).slice(-2) // 例如: "2023-04-05"
  return formattedDate
}
export const formatDate = (value: string | number | Date) => {
  const date = new Date(value)
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const h = date.getHours()
  const m = date.getMinutes()
  const s = date.getSeconds()

  const formattedDate =
    year +
    '-' +
    ('0' + month).slice(-2) +
    '-' +
    ('0' + day).slice(-2) +
    ' ' +
    ('0' + h).slice(-2) +
    ':' +
    ('0' + m).slice(-2) +
    ':' +
    ('0' + s).slice(-2) // 例如: "2023-04-05"
  return formattedDate
}

export const formatDay = (value: number) => {
  const date = Date.now()
  const hdbfvh = 24 * 60 * 60 * 1000 * value
  const hsdbhj = date - hdbfvh
  const jshdgh = new Date(hsdbhj)
  const year = jshdgh.getFullYear()
  const month = jshdgh.getMonth() + 1
  const day = jshdgh.getDate()

  const formattedDate = year + '-' + ('0' + month).slice(-2) + '-' + ('0' + day).slice(-2) // 例如: "2023-04-05"
  return formattedDate
}

export const formatTime = (value: number) => {
  const date = Date.now()
  const hdbfvh = 15 * 60 * 1000 * value
  const hsdbhj = date - hdbfvh
  const jshdgh = new Date(hsdbhj)
  const year = jshdgh.getFullYear()
  const month = jshdgh.getMonth() + 1
  const day = jshdgh.getDate()
  const h = jshdgh.getHours()
  const m = jshdgh.getMinutes()
  const s = jshdgh.getSeconds()

  const formattedDate =
    year +
    '-' +
    ('0' + month).slice(-2) +
    '-' +
    ('0' + day).slice(-2) +
    ' ' +
    ('0' + h).slice(-2) +
    ':' +
    ('0' + m).slice(-2) +
    ':' +
    ('0' + s).slice(-2) // 例如: "2023-04-05"
  return formattedDate
}

export const getTimestamp = (value: string) => {
  return new Date(value).getTime()
}
